package com.hns.can.report.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hns.can.common.constants.GlobalConst;
import com.hns.can.common.entity.BaseEntity;
import com.hns.can.common.formula.FillCodeDscValue;
import com.hns.can.common.formula.FillParamsVo;
import com.hns.can.master.entity.BaseCarInfoEntity;
import com.hns.can.master.entity.BaseDrvInfoEntity;
import com.hns.can.report.entity.BiDriverIdxInfoEntity;
import com.hns.can.report.vo.DrvAnaDrvVo;
import com.hns.can.report.vo.RelatedCarVo;
import com.hns.frame.mybatis.Pagination;
import com.hns.frame.service.CommonService;
import com.hns.tool.pub.PubUtil;

/**
 * 驾驶员画像
 * @author:lan
 * @email:763836737@qq.com
 * @version Revision 2.0.0
 */
@Service
public class DrvAnaService extends CommonService {
    
   /**
    * 填充代码描述
    */
    @Autowired
    private FillCodeDscValue codeDscValue;
    
   /**
    * 获取驾驶员信息
    * @param carId
    * @return
    * @throws Exception
    * @author:lan
    * @email:763836737@qq.com
    */
    @SuppressWarnings({"unchecked"})
    public List<BaseEntity> getDrvAnaDrvInfo(String drvId) throws Exception {
          List<BaseEntity> list = PubUtil.convertListMapToObject(
             		this.sqlMapDao.selectList("drvAna.getDrvAnaDrvInfo", drvId), BaseDrvInfoEntity.class);
          Map<String,String> map2 = new HashMap<String,String>();
          map2.put("organName", GlobalConst.DEFAULT_CACHE_VALUE);   
          FillParamsVo vo2 = new FillParamsVo("organId", map2);
          codeDscValue.fillInfoValue(list, new String[] {GlobalConst.CACHE_KEY_BASE_ORGAN},vo2);
          Map<String,String> mapTmp = new HashMap<String,String>();
          mapTmp.put("gender", "SEX00000");
          mapTmp.put("st", "EMS00000");
          mapTmp.put("driLicType", "DLT00000");
          mapTmp.put("cultuDgr", "DOE00000");
          codeDscValue.fillCodeDscValue(list, mapTmp);
          return list;
    }
    
    
    
   /**
    * 驾驶员车辆 在线车辆 (暂时无用)
    * @param drvId
    * @return
    * @throws Exception
    * @author:lan
    * @email:763836737@qq.com
    */
    @SuppressWarnings("unchecked")
    @Transactional
    public DrvAnaDrvVo getDrvCar(String drvId) throws Exception {
         List<DrvAnaDrvVo> list = PubUtil.convertListMapToObject(
            this.sqlMapDao.selectList("drvAna.getDrvCar", drvId), DrvAnaDrvVo.class);
		return list.get(0);
    }
     
   /**
    * 车辆列表
    * @param drvId
    * @return
    * @throws Exception
    * @author:lan
    * @email:763836737@qq.com
    */
    @Transactional
    public Pagination getRelatedCarPage(DrvAnaDrvVo drvVo) throws Exception {
        Pagination page = this.myBatisPage("drvAna.getRelatedCarCnt", "drvAna.getRelatedCarList", drvVo,RelatedCarVo.class);
        return page;
    }
     
   /**
    * 查询列表数据
    * @param vo
    * @return
    * @throws Exception
    * @author:lan
    * @email:763836737@qq.com
    */
    @SuppressWarnings("unchecked")
    public List<BiDriverIdxInfoEntity> getDrvIdxInfo(DrvAnaDrvVo vo) throws Exception {
         List<BiDriverIdxInfoEntity>  list =  PubUtil.convertListMapToObject(
             this.sqlMapDao.selectList("drvAna.getDrvIdxInfo", vo), BiDriverIdxInfoEntity.class);
         return list;
    }
     
   /**
    * 查询排名
    * @return
    * @throws Exception
    * @author:lan
    * @email:763836737@qq.com
    */
    @SuppressWarnings("unchecked")
    public List<Map<String,Object>> getDrvAnaRank(DrvAnaDrvVo vo) throws Exception {
        List<Map<String,Object>>  list =  this.sqlMapDao.selectList("drvAna.getDrvAnaRank", vo) ;
        return list;
    }
      
   /**
    * 趋势图
    * @param vo
    * @return
    * @throws Exception
    * @author:lan
    * @email:763836737@qq.com
    */
    @SuppressWarnings("unchecked")
    public List<Map<String,Object>> getDrvTrendInfo(DrvAnaDrvVo vo) throws Exception {
     List<Map<String,Object>> list = this.sqlMapDao.selectList("drvAna.getDrvTrendInfo", vo);
        return list;
    }
      
   /**
    * 查询能耗排名
    * @return
    * @throws Exception
    * @author:lan
    * @email:763836737@qq.com
    */
    @SuppressWarnings("unchecked")
    public List<Map<String,Object>> getDrvEnerRankInfo(DrvAnaDrvVo vo) throws Exception {
    	List<Map<String,Object>> list = this.sqlMapDao.selectList("drvAna.getDrvEnerRankInfo", vo) ;
        return list;
    }
    
    /**
     * 查询行为排名
     * @return
     * @throws Exception
     * @author:lan
     * @email:763836737@qq.com
     */
     @SuppressWarnings("unchecked")
     public List<Map<String,Object>> getDrvBehRankInfo(DrvAnaDrvVo vo) throws Exception {
     	List<Map<String,Object>> list = this.sqlMapDao.selectList("drvAna.getDrvBehRankInfo", vo) ;
         return list;
     }
     
    /**
     * 查询能耗排名
     * @return
     * @throws Exception
     * @author:lan
     * @email:763836737@qq.com
     */
     @SuppressWarnings("unchecked")
     public List<Map<String,Object>> getDrvEnergySpdAna(DrvAnaDrvVo vo) throws Exception {
         List<Map<String,Object>>  list =  this.sqlMapDao.selectList("drvAna.getDrvEnergySpdAna", vo) ;
         return list;
    }
     
    /**
     * 考勤
     * @param drvId
     * @return
     * @throws Exception
     * @author:lan
     * @email:763836737@qq.com
     */
     @Transactional
     public Pagination getDrvAttnPage(DrvAnaDrvVo drvVo) throws Exception {
         Pagination page = this.myBatisPage("drvAna.getDrvAttnCnt", "drvAna.getDrvAttnList", drvVo,BaseDrvInfoEntity.class);
         Map<String,String> map2 = new HashMap<String,String>();
         map2.put("lineName", GlobalConst.DEFAULT_CACHE_VALUE);   
         FillParamsVo vo2 = new FillParamsVo("lineId", map2);
         Map<String,String> map3 = new HashMap<String,String>();
         map3.put("drvName", GlobalConst.DEFAULT_CACHE_VALUE);   
         FillParamsVo vo3 = new FillParamsVo("drvId", map3);
         Map<String,String> map4 = new HashMap<String,String>();
         map4.put("licPltNo", GlobalConst.DEFAULT_CACHE_VALUE);   
         FillParamsVo vo4 = new FillParamsVo("carId", map4);
         codeDscValue.fillInfoValue(page.getData(), new String[] {GlobalConst.CACHE_KEY_BASE_LINE_INFO,GlobalConst.CACHE_KEY_BASE_DRV_INFO,GlobalConst.CACHE_KEY_BASE_CAR_INFO},vo2,vo3,vo4);
         return page;
     }
     
     /**
      * 获取考勤信息查询时间
      * @param tmpDateStr
      * @return
      * @throws Exception
      * @author:lan
      * @email:763836737@qq.com
      */
     @SuppressWarnings("unchecked")
     public DrvAnaDrvVo getAttnTime (DrvAnaDrvVo drvVo) throws Exception {
          List<DrvAnaDrvVo> list = PubUtil.convertListMapToObject(
              this.sqlMapDao.selectList("drvAna.getAttnTime", drvVo), DrvAnaDrvVo.class);
         return list.get(0);
     }
     
}
